package com.tanhua.server.controller;

import com.tanhua.server.service.MovementsMQService;
import com.tanhua.server.service.MovementsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("comments")
public class CommentsController {
    @Autowired
    private MovementsService movementsService;
    @Autowired
    private MovementsMQService movementsMQService;
    /**
     * 接口名称：评论列表
     * 接口路径：GET/comments
     */
    @GetMapping
    public ResponseEntity<Object> queryCommentsList(
            String movementId,
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize){
        return movementsService.queryCommentsList(movementId,page,pagesize);
    }

    /**
     * 接口名称：评论-提交
     * 接口路径：POST/comments
     */
    @PostMapping
    public ResponseEntity<Object> saveComments(@RequestBody Map<String,String> map){
        // 获取请求参数：动态id、评论内容
        String movementId = map.get("movementId");
        String comment = map.get("comment");
        // 发送mq消息
        movementsMQService.commentPublishMsg(movementId);
        return movementsService.saveComments(movementId,comment);
    }
}
